#include "CInGameScene.h"
namespace game
{
	namespace scene
	{
		CInGameScene::~CInGameScene()
		{

		}

		CInGameScene::CInGameScene(scene::SGameSceneEntry* entry, irr::scene::ISceneManager* sceneManager, game::video::IVideoHandler* videoHandler)
			:	CBaseScene(entry, sceneManager, videoHandler), 
			Character(0),
			Camera(0)
		{
		}

		void CInGameScene::establishScene()
		{
			//
			//irr::core::list<SDynamicObjectEntry*>::Iterator itDO = TypedEntry->DynamicObjects.begin();

			//while(itDO != TypedEntry->DynamicObjects->last())
			//{
				
				//itDO++;
			//}
			int i = 0;
		}


		void CInGameScene::addChild(IGameObject* gameObj)
		{
			switch(gameObj->getType())
			{
			case scene::EGO_CHARACTER:
				{
					this->Character = (IDynamicObject*)gameObj;
					DynamicObjects.push_back((IDynamicObject*)gameObj);
					//	Camera = this->GameSceneManager->getSceneManager()->addCameraSceneNode(0, irr::core::vector3df(0,50,100),irr::core::vector3df(0,50,0));
					//	Camera = this->GameSceneManager->getSceneManager()->addCameraSceneNodeFPS();
					break;
				}
			case scene::EGO_WORLD:
				{
					
				}
			default:
				{
					IGameObject::addChild(gameObj);
					break;
				}
			}

		}
		//
		//	bool CInGameScene::onUserAction(SUserAction action)
		//	{
		//		bool result = false;
		//
		//		if(action.KeyState == KEY_STATE_DOWN || action.KeyState == KEY_STATE_PRESSED)
		//		{
		//			switch(action.KeyCode)
		//			{
		//			case irr::KEY_CIRCLE:
		//				{
		//					
		//					if(this->Character)
		//					{
		//						irr::core::vector3df scale = this->Character->getScale();
		//
		//						ScalePercentage += ScalePercentage * 0.1f;
		//
		//						this->Character->setScale(scale * 1.1f);
		//
		//						if(this->EditBox)
		//						{
		//							int val = ScalePercentage / 100;
		//							irr::core::stringw scaleStr = irr::core::stringw("Scale: ")+irr::core::stringw(val);
		//							this->EditBox->setText(scaleStr.c_str());
		//						}
		//
		//					}
		//
		//					result = true;
		//					break;
		//				}
		//			case irr::KEY_CROSS:
		//				{
		//
		//					if(this->Character)
		//					{
		//						irr::core::vector3df scale = this->Character->getScale();
		//
		//						ScalePercentage -= ScalePercentage * 0.1f;
		//
		//						this->Character->setScale(scale * 0.9f);
		//
		//						if(this->EditBox)
		//						{
		//							int val = ScalePercentage / 100;
		//							irr::core::stringw scaleStr = irr::core::stringw("Scale: ")+irr::core::stringw(val);
		//							this->EditBox->setText(scaleStr.c_str());
		//						}
		//					}
		//
		//					result = true;
		//					break;
		//				}
		//			case irr::KEY_RIGHT:
		//				{
		//
		//					if(this->Character)
		//					{
		//						irr::core::vector3df rotation = this->Character->getRotation();
		//
		//						this->Character->getSceneNode()->setRotation(rotation + irr::core::vector3df(0, 5, 0));
		//						
		//					}
		//
		//					result = true;
		//					break;				
		//				}
		//			case irr::KEY_LEFT:
		//				{
		//					if(this->Character)
		//					{
		//						irr::core::vector3df rotation = this->Character->getRotation();
		//
		//						this->Character->setRotation(rotation + irr::core::vector3df(0, -5, 0));
		//
		//					}
		//					result = true;
		//					break;
		//				}
		//			case irr::KEY_DOWN:
		//				{
		//					//Camera = this->GameSceneManager->getSceneManager()->addCameraSceneNode(this->Character->getSceneNode(), irr::core::vector3df(0,60,60),irr::core::vector3df(0,30,0));
		//					
		//					result = true;
		//					break;				
		//				}
		//			case irr::KEY_TRIANGLE:
		//				{
		//					
		//					irr::scene::IAnimatedMesh* levelAnimMesh = this->GameSceneManager->getSceneManager()->getMesh("./data/meshes/terrain/1_1.b3d");
		//					irr::scene::IMesh* levelMesh = levelAnimMesh->getMesh(0);
		//
		//					irr::scene::ISceneNode* levelNode = 0;
		//
		//					if(levelMesh)
		//						levelNode = this->GameSceneManager->getSceneManager()->addMeshSceneNode(levelMesh);
		//
		//					irr::scene::ITriangleSelector* selector = 0;
		//
		//					if(levelNode)
		//					{
		//						levelNode->setPosition(irr::core::vector3df(-400,-80,-400));
		//						levelNode->setMaterialFlag(irr::video::EMF_LIGHTING, false);
		//						irr::video::ITexture* texture0 = this->GameSceneManager->getSceneManager()->getVideoDriver()->getTexture("./data/textures/terrain/neutral-stone.jpg");
		//						if(texture0)
		//							levelNode->setMaterialTexture(0,texture0) ;
		//
		//						selector = this->GameSceneManager->getSceneManager()->createTriangleSelector(levelMesh, levelNode);
		//						levelNode->setTriangleSelector(selector);
		//					}
		//
		//					if(selector)
		//					{
		//						irr::scene::ISceneNodeAnimator* anim = this->GameSceneManager->getSceneManager()->createCollisionResponseAnimator(	selector, 
		//							this->Character->getSceneNode(), 
		//							irr::core::vector3df(1,0.5f,1),
		//							irr::core::vector3df(0,-1,0), 
		//							irr::core::vector3df(0,0,0));
		//						selector->drop();
		//						this->Character->getSceneNode()->addAnimator(anim);
		//						anim->drop();
		//					}
		//					
		//					//Camera = this->GameSceneManager->getSceneManager()->addCameraSceneNode(this->Character->getSceneNode(), irr::core::vector3df(0,60,60),irr::core::vector3df(0,30,0));
		//
		//					result = true;
		//					break;
		//				}
		//			default:
		//				{
		//					result = false;
		//					break;
		//				}
		//			}
		//		}
		//		return result;
		//	}
		//
		//	void CInGameScene::establishControls()
		//	{
		//		
		//		EditBox = game::getDeviceManager()->getGUIEnvironment()->addEditBox(L"", irr::core::rect<s32>(0,0,100,50),true);
		//
		//		//game::getDeviceManager()->getGUIEnvironment()->addStaticText(L"TEXT", irr::core::rect<s32>(0,0,200,200),true);
		//	}



	}
}
